package com.binest.inclusionExamine.service.impl;



import com.binest.common.core.domain.entity.SysUser;
import com.binest.common.core.page.TableDataInfo;
import com.binest.common.utils.DateUtils;
import com.binest.common.utils.StringUtils;
import com.binest.common.utils.uuid.IdUtils;
import com.binest.figureInclusion.domain.FigureInclusion;
import com.binest.figureInclusion.mapper.FigureInclusionMapper;
import com.binest.figureInclusion.service.IFigureInclusionService;
import com.binest.figureInclusionMain.domain.FigureInclusionMain;
import com.binest.figureInclusionMain.mapper.FigureInclusionMainMapper;
import com.binest.foreignInvest.domain.ForeignInvest;
import com.binest.foreignInvest.mapper.ForeignInvestMapper;
import com.binest.hackathonInclusion.domain.HackathonInclusion;
import com.binest.hackathonInclusion.mapper.HackathonInclusionMapper;
import com.binest.hackathonInclusion.service.IHackathonInclusionService;
import com.binest.hackathonInclusionMain.domain.HackathonInclusionMain;
import com.binest.hackathonInclusionMain.mapper.HackathonInclusionMainMapper;
import com.binest.inclusionExamine.domain.InclusionExamine;
import com.binest.inclusionExamine.mapper.InclusionExamineMapper;
import com.binest.inclusionExamine.service.IInclusionExamineService;
import com.binest.investDetails.domain.InvestDetails;
import com.binest.investDetails.mapper.InvestDetailsMapper;
import com.binest.investorInclusion.domain.InvestorInclusion;
import com.binest.investorInclusion.mapper.InvestorInclusionMapper;
import com.binest.investorInclusion.service.IInvestorInclusionService;
import com.binest.investorInclusionMain.domain.InvestorInclusionMain;
import com.binest.investorInclusionMain.mapper.InvestorInclusionMainMapper;
import com.binest.keyEvent.domain.KeyEvent;
import com.binest.keyEvent.mapper.KeyEventMapper;
import com.binest.kolInclusion.domain.KolInclusion;
import com.binest.kolInclusion.mapper.KolInclusionMapper;
import com.binest.kolInclusion.service.IKolInclusionService;
import com.binest.kolInclusionMain.domain.KolInclusionMain;
import com.binest.kolInclusionMain.mapper.KolInclusionMainMapper;
import com.binest.meetingInclusion.domain.MeetingInclusion;
import com.binest.meetingInclusion.mapper.MeetingInclusionMapper;
import com.binest.meetingInclusion.service.IMeetingInclusionService;
import com.binest.meetingInclusionMain.domain.MeetingInclusionMain;
import com.binest.meetingInclusionMain.mapper.MeetingInclusionMainMapper;
import com.binest.projectInclusion.domain.ProjectInclusion;
import com.binest.projectInclusion.mapper.ProjectInclusionMapper;
import com.binest.projectInclusion.service.IProjectInclusionService;
import com.binest.projectInclusionMain.domain.ProjectInclusionMain;
import com.binest.projectInclusionMain.mapper.ProjectInclusionMainMapper;
import com.binest.projectInvestDetails.domain.ProjectInvestDetails;
import com.binest.projectInvestDetails.domain.ProjectInvestDetailsInvestors;
import com.binest.projectInvestDetails.mapper.ProjectInvestDetailsMapper;
import com.binest.socialMediaConnection.domain.SocialMediaConnection;
import com.binest.socialMediaConnection.mapper.SocialMediaConnectionMapper;
import com.binest.system.service.ISysUserService;
import com.binest.system.webMessage.domain.WebMessage;
import com.binest.system.webMessage.mapper.WebMessageMapper;
import com.binest.toolInclusion.domain.ToolInclusion;
import com.binest.toolInclusion.mapper.ToolInclusionMapper;
import com.binest.toolInclusion.service.IToolInclusionService;
import com.binest.toolInclusionMain.domain.ToolInclusionMain;
import com.binest.toolInclusionMain.mapper.ToolInclusionMainMapper;
import com.binest.util.ElasticsearchHandle;

import com.binest.winnersList.domain.WinnersList;
import com.binest.winnersList.mapper.WinnersListMapper;
import com.binest.workExperience.domain.WorkExperience;
import com.binest.workExperience.mapper.WorkExperienceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 收录审核Service业务层处理
 *
 * @author binest
 * @date 2024-01-04
 */
@Service
public class InclusionExamineServiceImpl implements IInclusionExamineService
{
    @Autowired
    private InclusionExamineMapper inclusionExamineMapper;
    @Autowired
    private MeetingInclusionMapper meetingInclusionMapper;

    @Autowired
    private MeetingInclusionMainMapper meetingInclusionMainMapper;

    @Autowired
    private KolInclusionMapper kolInclusionMapper;
    @Autowired
    private KolInclusionMainMapper kolInclusionMainMapper;

    @Autowired
    private SocialMediaConnectionMapper socialMediaConnectionMapper;


    @Autowired
    private FigureInclusionMapper figureInclusionMapper;

    @Autowired
    private FigureInclusionMainMapper figureInclusionMainMapper;


    @Autowired
    private WorkExperienceMapper workExperienceMapper;
    @Autowired
    private InvestDetailsMapper investDetailsMapper;

    @Autowired
    private HackathonInclusionMapper hackathonInclusionMapper;

    @Autowired
    private WinnersListMapper winnersListMapper;

    @Autowired
    private HackathonInclusionMainMapper hackathonInclusionMainMapper;


    @Autowired
    private ToolInclusionMapper toolInclusionMapper;

    @Autowired
    private ToolInclusionMainMapper toolInclusionMainMapper;


    @Autowired
    private InvestorInclusionMapper investorInclusionMapper;
    @Autowired
    private InvestorInclusionMainMapper investorInclusionMainMapper;

    @Autowired
    private KeyEventMapper keyEventMapper;


    @Autowired
    private ProjectInclusionMapper projectInclusionMapper;

    @Autowired
    private ProjectInclusionMainMapper projectInclusionMainMapper;


    @Autowired
    private ProjectInvestDetailsMapper projectInvestDetailsMapper;
    @Autowired
    private ForeignInvestMapper foreignInvestMapper;


    @Autowired
    private IProjectInclusionService projectInclusionService;
    @Autowired
    private IInvestorInclusionService investorInclusionService;
    @Autowired
    private IFigureInclusionService figureInclusionService;
    @Autowired
    private IMeetingInclusionService meetingInclusionService;
    @Autowired
    private IKolInclusionService kolInclusionService;
    @Autowired
    private IToolInclusionService toolInclusionService;
    @Autowired
    private IHackathonInclusionService hackathonInclusionService;
    @Autowired
    private WebMessageMapper webMessageMapper;
    @Autowired
    private ISysUserService userService;
    /**
     * 查询收录审核
     *
     * @param id 收录审核主键
     * @return 收录审核
     */
    @Override
    public InclusionExamine selectInclusionExamineById(String id)
    {
        return inclusionExamineMapper.selectInclusionExamineById(id);
    }

    /**
     * 查询收录审核列表
     *
     * @param inclusionExamine 收录审核
     * @return 收录审核
     */
    @Override
    public List<InclusionExamine> selectInclusionExamineList(InclusionExamine inclusionExamine)
    {
        return inclusionExamineMapper.selectInclusionExamineList(inclusionExamine);
    }

    @Override
    public TableDataInfo selectMyInclusionExamineList(InclusionExamine inclusionExamine) {

        TableDataInfo rspData = new TableDataInfo();
        //判断收录类型
//        inclusionExamine.setUserId(StpUtil.getLoginId().toString());
        //查询当前类型的审核列表列表
//        List<InclusionExamine> inclusionExamineList=new ArrayList<>();
//        inclusionExamineList=inclusionExamineMapper.selectInclusionExamineList(inclusionExamine);
//
//        if(inclusionExamineList.size()>0){
//            //项目
//            if(inclusionExamine.getType().equals("0")){
//                List<ProjectInclusion>  proList=new ArrayList<>();
//                for(int a=0;a<inclusionExamineList.size();a++){
//                    ProjectInclusion pro= projectInclusionService.selectProjectInclusionById(inclusionExamineList.get(a).getProjectId());
//                    pro.setStatus(inclusionExamineList.get(a).getStatus());
//
//                    proList.add(pro);
//                }
//                rspData.setRows(proList);
//            }else if(inclusionExamine.getType().equals("1")){
//                List<InvestorInclusion>  invList=new ArrayList<>();
//                //投资机构
//                for(int a=0;a<inclusionExamineList.size();a++){
//                    InvestorInclusion inv= investorInclusionService.selectInvestorInclusionById(inclusionExamineList.get(a).getProjectId());
//                    inv.setStatus(inclusionExamineList.get(a).getStatus());
//                    invList.add(inv);
//                }
//                rspData.setRows(invList);
//            }else if(inclusionExamine.getType().equals("2")){
//                List<FigureInclusion>  figList=new ArrayList<>();
//                //人物
//                for(int a=0;a<inclusionExamineList.size();a++){
//                    FigureInclusion fig= figureInclusionService.selectFigureInclusionById(inclusionExamineList.get(a).getProjectId());
//                    fig.setStatus(inclusionExamineList.get(a).getStatus());
//                    figList.add(fig);
//                }
//                rspData.setRows(figList);
//            }else if(inclusionExamine.getType().equals("3")){
//                List<MeetingInclusion>  meetList=new ArrayList<>();
//                //会议
//                for(int a=0;a<inclusionExamineList.size();a++){
//                    MeetingInclusion meet= meetingInclusionService.selectMeetingInclusionById(inclusionExamineList.get(a).getProjectId());
//                    meet.setStatus(inclusionExamineList.get(a).getStatus());
//                    meetList.add(meet);
//                }
//                rspData.setRows(meetList);
//            }else if(inclusionExamine.getType().equals("4")){
//                List<KolInclusion>  kolList=new ArrayList<>();
//                //kol
//                for(int a=0;a<inclusionExamineList.size();a++){
//                    KolInclusion kol= kolInclusionService.selectKolInclusionById(inclusionExamineList.get(a).getProjectId());
//                    kol.setStatus(inclusionExamineList.get(a).getStatus());
//                    kolList.add(kol);
//                }
//                rspData.setRows(kolList);
//            }else if(inclusionExamine.getType().equals("5")){
//                //其他分为工具和黑客马拉松
//                //工具
//                List<OtherVo>  otherList=new ArrayList<>();
//                inclusionExamine.setType("6");
//                inclusionExamineList =inclusionExamineMapper.selectInclusionExamineList(inclusionExamine);
//
//                if(inclusionExamineList.size()>0){
//                    for(int a=0;a<inclusionExamineList.size();a++){
//                        ToolInclusion tool= toolInclusionService.selectToolInclusionByMaidId(inclusionExamineList.get(a).getProjectId(),inclusionExamine.getLang());
//                        OtherVo other=new  OtherVo();
//                        other.setId(tool.getId());
//                        other.setMainId(tool.getMainId());
//                        other.setName(tool.getName());
//                        other.setLogoUrl(tool.getLogoUrl());
//                        other.setLabel(tool.getLabel());
//                        other.setSynopsis(tool.getSynopsis());
//                        other.setStatus(inclusionExamineList.get(a).getStatus());
//                        otherList.add(other);
//                    }
//                }
//                //黑客马拉松
//                inclusionExamine.setType("7");
//                inclusionExamineList =inclusionExamineMapper.selectInclusionExamineList(inclusionExamine);
//                if(inclusionExamineList.size()>0){
//                    for(int a=0;a<inclusionExamineList.size();a++){
//                        HackathonInclusion hack= hackathonInclusionService.selectHackathonInclusionById(inclusionExamineList.get(a).getProjectId());
//                        OtherVo other=new  OtherVo();
//                        other.setId(hack.getId());
//                        other.setMainId(hack.getMainId());
//                        other.setName(hack.getName());
//                        other.setLogoUrl(hack.getLogoUrl());
//                        other.setSynopsis(hack.getContent());
//                        other.setStatus(inclusionExamineList.get(a).getStatus());
//                        otherList.add(other);
//                    }
//
//                }
//
//                rspData.setRows(otherList);
//            }
//
//
//            rspData.setCode(HttpStatus.SUCCESS);
//            rspData.setMsg("查询成功");
//            rspData.setTotal(inclusionExamineList.size());
////            return rspData;
//        }else{
//            rspData.setRows(inclusionExamineList);
//            rspData.setCode(HttpStatus.SUCCESS);
//            rspData.setMsg("查询成功");
//            rspData.setTotal(0);
//            return rspData;
//        }

 return rspData;

    }


    /**
     * 新增收录审核
     *
     * @param inclusionExamine 收录审核
     * @return 结果
     */
    @Override
    public int insertInclusionExamine(InclusionExamine inclusionExamine)
    {
        inclusionExamine.setCreateTime(DateUtils.getNowDate());
        return inclusionExamineMapper.insertInclusionExamine(inclusionExamine);
    }

    /**
     * 修改收录审核
     *
     * @param inclusionExamine 收录审核
     * @return 结果
     */
    @Override
    public int updateInclusionExamine(InclusionExamine inclusionExamine)
    {
        inclusionExamine.setUpdateTime(DateUtils.getNowDate());
        return inclusionExamineMapper.updateInclusionExamine(inclusionExamine);
    }

    /**
     * 审核收录信息
     * @param inclusionExamine
     * @return
     */
    @Override
    public int examine(InclusionExamine inclusionExamine) throws Exception {
        //判断是否审核通过   1审核通过 已收录
        if(inclusionExamine.getStatus().equals("1")){
            //判断是那种项目类型  会议3
            if(inclusionExamine.getType().equals("3")){

                //当前会议收录信息
                MeetingInclusion meetingInclusion=meetingInclusionMapper.selectMeetingInclusionById(inclusionExamine.getProjectId());
                //判断是否是更新后审核操作
                if(meetingInclusion.getOldId()!=null){
                    //判断是否是同语言修改
                    if(meetingInclusion.getLang().equals(meetingInclusion.getOldLang())){
                        //同语言则直接取oldId 删除Es中数据
                        boolean deleRes= ElasticsearchHandle.deleteDocument("meeting_inclusion",meetingInclusion.getOldId());
                    }else{
                        //修改成不同语言数据  则需要查询与修改后语言类型相同并且时间最近已经审核通过的数据
                        MeetingInclusion newMeetingInclusion=new  MeetingInclusion();
                        newMeetingInclusion.setMainId(meetingInclusion.getMainId());
                        newMeetingInclusion.setLang(meetingInclusion.getLang());

                        List<MeetingInclusion>  resList=meetingInclusionMapper.selectMeetingInclusionList(newMeetingInclusion);
                        if(resList.size()>0){
                            boolean deleRes=ElasticsearchHandle.deleteDocument("meeting_inclusion",resList.get(0).getId());
                        }

                    }
                }
                MeetingInclusionMain meetingInclusionMain =meetingInclusionMainMapper.selectMeetingInclusionMainById(meetingInclusion.getMainId());
                meetingInclusion.setLikeCount(meetingInclusionMain.getLikeCount());
                meetingInclusion.setNolikeCount(meetingInclusionMain.getLikeCount());
                meetingInclusion.setQmHash(inclusionExamine.getQmHash());
                //查询会议数据存入es
            boolean res= ElasticsearchHandle.insertDocument("meeting_inclusion",meetingInclusion,inclusionExamine.getProjectId());
            //生成审核消息
                WebMessage webMessage =new WebMessage();
                webMessage.setId(IdUtils.simpleUUID());
                webMessage.setName(meetingInclusion.getTheme());
                webMessage.setInclusionMainId(meetingInclusion.getMainId());
                webMessage.setInclusionType("3");
                webMessage.setType("1");webMessage.setStatus("0");
                webMessage.setTitle("【审核】 会议收录");
                webMessage.setContent("关于您收录的   "+meetingInclusion.getTheme()+"审核已通过");
                webMessage.setUpdateBy(meetingInclusion.getCreateBy());
                webMessageMapper.insertWebMessage(webMessage);

            }else if(inclusionExamine.getType().equals("4")) {
                //kol
                KolInclusion kolInclusion=kolInclusionMapper.selectKolInclusionById(inclusionExamine.getProjectId());
                if(kolInclusion.getOldId()!=null){
                    //判断是否是同语言修改
                    if(kolInclusion.getLang().equals(kolInclusion.getOldLang())){
                        //同语言则直接取oldId 删除Es中数据
                        boolean deleRes=ElasticsearchHandle.deleteDocument("kol_inclusion",kolInclusion.getOldId());
                    }else{
                        //修改成不同语言数据  则需要查询与修改后语言类型相同并且时间最近已经审核通过的数据
                        KolInclusion newKolInclusion=new  KolInclusion();
                        newKolInclusion.setMainId(kolInclusion.getMainId());
                        newKolInclusion.setLang(kolInclusion.getLang());
                        List<KolInclusion>  resList=kolInclusionMapper.selectKolInclusionList(newKolInclusion);
                        if(resList.size()>0){
                            boolean deleRes=ElasticsearchHandle.deleteDocument("kol_inclusion",resList.get(0).getId());
                        }

                    }
                }
                //查询社媒链接
                SocialMediaConnection socialMediaConnection =new SocialMediaConnection();
                socialMediaConnection.setInclusionId(kolInclusion.getId());

                KolInclusionMain kolInclusionMain =kolInclusionMainMapper.selectKolInclusionMainById(kolInclusion.getMainId());
                kolInclusion.setLikeCount(kolInclusionMain.getLikeCount());
                kolInclusion.setNolikeCount(kolInclusionMain.getNolikeCount());
                kolInclusion.setSmcList(socialMediaConnectionMapper.selectSocialMediaConnectionList(socialMediaConnection));
                //查询会议数据存入es
                kolInclusion.setQmHash(inclusionExamine.getQmHash());
                boolean res=ElasticsearchHandle.insertDocument("kol_inclusion",kolInclusion,inclusionExamine.getProjectId());
                //生成审核消息
                WebMessage webMessage =new WebMessage();
                webMessage.setId(IdUtils.simpleUUID());
                webMessage.setName(kolInclusion.getNickname());
                webMessage.setInclusionMainId(kolInclusion.getMainId());
                webMessage.setInclusionType("4");
                webMessage.setType("1");webMessage.setStatus("0");
              webMessage.setTitle("【审核】 KOL收录");
              webMessage.setContent("关于您收录的   "+kolInclusion.getNickname()+"审核已通过");
                webMessage.setUpdateBy(kolInclusion.getCreateBy());
                webMessageMapper.insertWebMessage(webMessage);

            }
            else if(inclusionExamine.getType().equals("2")) {
                //人物收录
                FigureInclusion figureInclusion=figureInclusionMapper.selectFigureInclusionById(inclusionExamine.getProjectId());
                if(figureInclusion.getOldId()!=null){
                    //判断是否是同语言修改
                    if(figureInclusion.getLang().equals(figureInclusion.getOldLang())){
                        //同语言则直接取oldId 删除Es中数据
                        boolean deleRes=ElasticsearchHandle.deleteDocument("figure_inclusion",figureInclusion.getOldId());
                    }else{
                        //修改成不同语言数据  则需要查询与修改后语言类型相同并且时间最近已经审核通过的数据
                        FigureInclusion newFigureInclusion=new  FigureInclusion();
                        newFigureInclusion.setMainId(figureInclusion.getMainId());
                        newFigureInclusion.setLang(figureInclusion.getLang());
                        List<FigureInclusion>  resList=figureInclusionMapper.selectFigureInclusionList(newFigureInclusion);
                        if(resList.size()>0){
                            boolean deleRes=ElasticsearchHandle.deleteDocument("figure_inclusion",resList.get(0).getId());
                        }

                    }
                }
                //查询社媒链接
                SocialMediaConnection  socialMediaConnection =new SocialMediaConnection();
                socialMediaConnection.setInclusionId(figureInclusion.getId());
                //查询工作经历
//                    WorkExperience workExperience=new WorkExperience();
//                    workExperience.setInclusionId(figureInclusion.getId());
//                    List<WorkExperience> resList=    workExperienceMapper.selectWorkExperienceList(workExperience);
                //查询投资详情
                InvestDetails investDetails  =new InvestDetails();
                investDetails.setInclusionId(figureInclusion.getId());
                //查主表点赞数
                FigureInclusionMain figureInclusionMain =figureInclusionMainMapper.selectFigureInclusionMainById(figureInclusion.getMainId());
                 //保存
                figureInclusion.setLikeCount(figureInclusionMain.getLikeCount());
                figureInclusion.setNolikeCount(figureInclusionMain.getNolikeCount());
                figureInclusion.setSmcList(socialMediaConnectionMapper.selectSocialMediaConnectionList(socialMediaConnection));
//                figureInclusion.setWorkExperienceList(resList);
                figureInclusion.setInvestDetailsList(investDetailsMapper.selectInvestDetailsList(investDetails));
                //查询数据存入es
                figureInclusion.setQmHash(inclusionExamine.getQmHash());
                boolean res=ElasticsearchHandle.insertDocument("figure_inclusion",figureInclusion,inclusionExamine.getProjectId());
                //生成审核消息
                WebMessage webMessage =new WebMessage();
                webMessage.setId(IdUtils.simpleUUID());
                webMessage.setName(figureInclusion.getName());
                webMessage.setInclusionMainId(figureInclusion.getMainId());
                webMessage.setInclusionType("2");
                webMessage.setType("1");webMessage.setStatus("0");
              webMessage.setTitle("【审核】 人物收录");
              webMessage.setContent("关于您收录的   "+figureInclusion.getName()+"审核已通过");
                webMessage.setUpdateBy(figureInclusion.getCreateBy());
                webMessageMapper.insertWebMessage(webMessage);

            }else if(inclusionExamine.getType().equals("7")) {
                //黑客马拉松
                HackathonInclusion hackathonInclusion=hackathonInclusionMapper.selectHackathonInclusionById(inclusionExamine.getProjectId());

                if(hackathonInclusion.getOldId()!=null){
                    //判断是否是同语言修改
                    if(hackathonInclusion.getLang().equals(hackathonInclusion.getOldLang())){
                        //同语言则直接取oldId 删除Es中数据
                        boolean deleRes=ElasticsearchHandle.deleteDocument("hackathon_inclusion",hackathonInclusion.getOldId());
                    }else{
                        //修改成不同语言数据  则需要查询与修改后语言类型相同并且时间最近已经审核通过的数据
                        HackathonInclusion newHackathonInclusion=new  HackathonInclusion();
                        newHackathonInclusion.setMainId(hackathonInclusion.getMainId());
                        newHackathonInclusion.setLang(hackathonInclusion.getLang());
                        List<HackathonInclusion>  resList=hackathonInclusionMapper.selectHackathonInclusionList(newHackathonInclusion);
                        if(resList.size()>0){
                            boolean deleRes=ElasticsearchHandle.deleteDocument("hackathon_inclusion",resList.get(0).getId());
                        }

                    }
                }
                //查询获奖名单
                WinnersList wnnersList =new WinnersList();
                wnnersList.setInclusionId(hackathonInclusion.getId());

                HackathonInclusionMain hackathonInclusionMain =hackathonInclusionMainMapper.selectHackathonInclusionMainById(hackathonInclusion.getMainId());
                hackathonInclusion.setLikeCount(hackathonInclusionMain.getLikeCount());
                hackathonInclusion.setNolikeCount(hackathonInclusionMain.getNolikeCount());
                hackathonInclusion.setWinnersList(winnersListMapper.selectWinnersListList(wnnersList));
                //查询数据存入es
                hackathonInclusion.setQmHash(inclusionExamine.getQmHash());
                boolean res=ElasticsearchHandle.insertDocument("hackathon_inclusion",hackathonInclusion,inclusionExamine.getProjectId());
                //生成审核消息
                WebMessage webMessage =new WebMessage();
                webMessage.setId(IdUtils.simpleUUID());
                webMessage.setName(hackathonInclusion.getName());
                webMessage.setInclusionMainId(hackathonInclusion.getMainId());
                webMessage.setInclusionType("7");
                webMessage.setType("1");webMessage.setStatus("0");
              webMessage.setTitle("【审核】 黑客马拉松收录");
              webMessage.setContent("关于您收录的   "+hackathonInclusion.getName()+"审核已通过");
                webMessage.setUpdateBy(hackathonInclusion.getCreateBy());
                webMessageMapper.insertWebMessage(webMessage);
            }else if(inclusionExamine.getType().equals("6")) {
                //工具
                ToolInclusion toolInclusion=toolInclusionMapper.selectToolInclusionById(inclusionExamine.getProjectId());


                if(toolInclusion.getOldId()!=null){
                    //判断是否是同语言修改
                    if(toolInclusion.getLang().equals(toolInclusion.getOldLang())){
                        //同语言则直接取oldId 删除Es中数据
                        boolean deleRes=ElasticsearchHandle.deleteDocument("tool_inclusion",toolInclusion.getOldId());
                    }else{
                        //修改成不同语言数据  则需要查询与修改后语言类型相同并且时间最近已经审核通过的数据
                        ToolInclusion newToolInclusion=new  ToolInclusion();
                        newToolInclusion.setMainId(toolInclusion.getMainId());
                        newToolInclusion.setLang(toolInclusion.getLang());
                        List<ToolInclusion>  resList=toolInclusionMapper.selectToolInclusionList(newToolInclusion);
                        if(resList.size()>0){
                            boolean deleRes=ElasticsearchHandle.deleteDocument("tool_inclusion",resList.get(0).getId());
                        }

                    }
                }
                ToolInclusionMain toolInclusionMain =toolInclusionMainMapper.selectToolInclusionMainById(toolInclusion.getMainId());
                toolInclusion.setLikeCount(toolInclusionMain.getLikeCount());
                toolInclusion.setNolikeCount(toolInclusionMain.getNolikeCount());
                //查询数据存入es
                toolInclusion.setQmHash(inclusionExamine.getQmHash());
                boolean res=ElasticsearchHandle.insertDocument("tool_inclusion",toolInclusion,inclusionExamine.getProjectId());
                //生成审核消息
                WebMessage webMessage =new WebMessage();
                webMessage.setId(IdUtils.simpleUUID());
                webMessage.setName(toolInclusion.getName());
                webMessage.setInclusionMainId(toolInclusion.getMainId());
                webMessage.setInclusionType("6");
                webMessage.setType("1");webMessage.setStatus("0");
              webMessage.setTitle("【审核】 工具收录");
              webMessage.setContent("关于您收录的   "+toolInclusion.getName()+"审核已通过");
                webMessage.setUpdateBy(toolInclusion.getCreateBy());
                webMessageMapper.insertWebMessage(webMessage);
            } else if(inclusionExamine.getType().equals("1")) {
                //投资机构收录
                InvestorInclusion investorInclusion=investorInclusionMapper.selectInvestorInclusionById(inclusionExamine.getProjectId());
                if(investorInclusion.getOldId()!=null){
                    //判断是否是同语言修改
                    if(investorInclusion.getLang().equals(investorInclusion.getOldLang())){
                        //同语言则直接取oldId 删除Es中数据
                        boolean deleRes=ElasticsearchHandle.deleteDocument("investor_inclusion",investorInclusion.getOldId());
                    }else{
                        //修改成不同语言数据  则需要查询与修改后语言类型相同并且时间最近已经审核通过的数据
                        InvestorInclusion newInvestorInclusion=new  InvestorInclusion();
                        newInvestorInclusion.setMainId(investorInclusion.getMainId());
                        newInvestorInclusion.setLang(investorInclusion.getLang());
                        List<InvestorInclusion>  resList=investorInclusionMapper.selectInvestorInclusionList(newInvestorInclusion);
                        if(resList.size()>0){
                            boolean deleRes=ElasticsearchHandle.deleteDocument("investor_inclusion",resList.get(0).getId());
                        }
                    }
                }
                //查询工作经历
                WorkExperience workExperience=new WorkExperience();
                workExperience.setInclusionId(investorInclusion.getId());
                List<WorkExperience> resList=    workExperienceMapper.selectWorkExperienceList(workExperience);
                //查询社媒链接
                SocialMediaConnection  socialMediaConnection =new SocialMediaConnection();
                socialMediaConnection.setInclusionId(investorInclusion.getId());
                //查询关键事件
                KeyEvent keyEvent=new KeyEvent();
                keyEvent.setInclusionId(investorInclusion.getId());
                //查询投资详情
                InvestDetails   investDetails  =new InvestDetails();
                investDetails.setInclusionId(investorInclusion.getId());
                //查主表点赞数
                InvestorInclusionMain investorInclusionMain =investorInclusionMainMapper.selectInvestorInclusionMainById(investorInclusion.getMainId());
                //保存
                investorInclusion.setLikeCount(investorInclusionMain.getLikeCount());
                investorInclusion.setNolikeCount(investorInclusionMain.getNolikeCount());
                investorInclusion.setSmcList(socialMediaConnectionMapper.selectSocialMediaConnectionList(socialMediaConnection));
                investorInclusion.setEventList(keyEventMapper.selectKeyEventList(keyEvent));
                investorInclusion.setWorkExperienceList(resList);
                investorInclusion.setInvestDetailsList(investDetailsMapper.selectInvestDetailsList(investDetails));
                //查询会议数据存入es
                investorInclusion.setQmHash(inclusionExamine.getQmHash());
                boolean res=ElasticsearchHandle.insertDocument("investor_inclusion",investorInclusion,inclusionExamine.getProjectId());
                //生成审核消息
                WebMessage webMessage =new WebMessage();
                webMessage.setId(IdUtils.simpleUUID());
                webMessage.setName(investorInclusion.getName());
                webMessage.setInclusionMainId(investorInclusion.getMainId());
                webMessage.setInclusionType("1");
                webMessage.setType("1");webMessage.setStatus("0");
                webMessage.setTitle("【审核】 投资机构收录");
                webMessage.setContent("关于您收录的   "+investorInclusion.getName()+"审核已通过");
                webMessage.setUpdateBy(investorInclusion.getCreateBy());
                webMessageMapper.insertWebMessage(webMessage);
            }
            else if(inclusionExamine.getType().equals("0")) {

                //项目收录
                ProjectInclusion projectInclusion=projectInclusionMapper.selectProjectInclusionById(inclusionExamine.getProjectId());
                if(projectInclusion.getOldId()!=null){
                    //判断是否是同语言修改
                    if(projectInclusion.getLang().equals(projectInclusion.getOldLang())){
                        //同语言则直接取oldId 删除Es中数据
                        boolean deleRes=ElasticsearchHandle.deleteDocument("project_inclusion",projectInclusion.getOldId());
                    }else{
                        //修改成不同语言数据  则需要查询与修改后语言类型相同并且时间最近已经审核通过的数据
                        InvestorInclusion newInvestorInclusion=new  InvestorInclusion();
                        newInvestorInclusion.setMainId(projectInclusion.getMainId());
                        newInvestorInclusion.setLang(projectInclusion.getLang());
                        List<InvestorInclusion>  resList=investorInclusionMapper.selectInvestorInclusionList(newInvestorInclusion);
                        if(resList.size()>0){
                            boolean deleRes=ElasticsearchHandle.deleteDocument("project_inclusion",resList.get(0).getId());
                        }
                    }
                }

                //查询工作经历
                    WorkExperience workExperience=new WorkExperience();
                    workExperience.setInclusionId(projectInclusion.getId());
                    List<WorkExperience> resList=    workExperienceMapper.selectWorkExperienceList(workExperience);
                //查询社媒链接
                SocialMediaConnection  socialMediaConnection =new SocialMediaConnection();
                socialMediaConnection.setInclusionId(projectInclusion.getId());
                //查询关键事件
                KeyEvent keyEvent=new KeyEvent();
                keyEvent.setInclusionId(projectInclusion.getId());
                //查询投资详情
                ProjectInvestDetails projectInvestDetails  =new ProjectInvestDetails();
                projectInvestDetails.setInclusionId(projectInclusion.getId());
                //对外投资
                ForeignInvest foreignInvest  =new  ForeignInvest();
                foreignInvest.setInclusionId(projectInclusion.getId());
                //查主表点赞数
                ProjectInclusionMain projectInclusionMain =projectInclusionMainMapper.selectProjectInclusionMainById(projectInclusion.getMainId());
                //保存
                projectInclusion.setLikeCount(projectInclusionMain.getLikeCount());
                projectInclusion.setNolikeCount(projectInclusionMain.getNolikeCount());
                projectInclusion.setSmcList(socialMediaConnectionMapper.selectSocialMediaConnectionList(socialMediaConnection));
                projectInclusion.setEventList(keyEventMapper.selectKeyEventList(keyEvent));
                projectInclusion.setProjectInvestDetailsList(projectInvestDetailsMapper.selectProjectInvestDetailsList(projectInvestDetails));
                if(projectInclusion.getProjectInvestDetailsList()!=null&& projectInclusion.getProjectInvestDetailsList().size()>0){
                    ProjectInvestDetails pd = null;
                    List<ProjectInvestDetails> newPList = new ArrayList<>();
                    for (int i=0;i<projectInclusion.getProjectInvestDetailsList().size(); i++){
                        pd = projectInclusion.getProjectInvestDetailsList().get(i);
                        //ProjectInvestDetailsInvestors
                        if(StringUtils.hasText(pd.getInvestor())){
                            List<ProjectInvestDetailsInvestors> iList = projectInvestDetailsMapper.selectProjectInvestDetailsInvestorsByPId(pd.getId());
                            pd.setProjectInvestDetailsInvestors(iList);
                        }
                        newPList.add(pd);
                    }
                    projectInclusion.setProjectInvestDetailsList(newPList);
                }
                projectInclusion.setForeignInvestList(foreignInvestMapper.selectForeignInvestList(foreignInvest));
                projectInclusion.setWorkExperienceList(resList);
                //查询数据存入es
                projectInclusion.setQmHash(inclusionExamine.getQmHash());
                boolean res=ElasticsearchHandle.insertDocument("project_inclusion",projectInclusion,inclusionExamine.getProjectId());
                //生成审核消息
                WebMessage webMessage =new WebMessage();
                webMessage.setId(IdUtils.simpleUUID());
                webMessage.setName(projectInclusion.getName());
                webMessage.setInclusionMainId(projectInclusion.getMainId());
                webMessage.setInclusionType("0");
                webMessage.setType("1");webMessage.setStatus("0");
              webMessage.setTitle("【审核】 项目收录");
              webMessage.setContent("关于您收录的   "+projectInclusion.getName()+"审核已通过");
                webMessage.setUpdateBy(projectInclusion.getCreateBy());
                webMessageMapper.insertWebMessage(webMessage);
            }
        }
//        inclusionExamine.setUpdateTime(DateUtils.getNowDate());
        //获取审核人
        SysUser sysUser = userService.selectUserByAddress(inclusionExamine.getAddress());
        inclusionExamine.setUserId(String.valueOf(sysUser.getUserId()));
        inclusionExamine.setExamineName(sysUser.getNickName());
        return inclusionExamineMapper.updateInclusionExamine(inclusionExamine);
    }

    @Override
    public String getExamineStatus(String projectId) {
        //0:待审核，1：审核通过，2：已拒绝，3，申诉中，4：申诉成功-->审核通过，5:申诉失败-->已拒绝,6:投票中,7：投票成功，8：投票失败  9更新中
        String  res="";
       String  status=inclusionExamineMapper.getExamineStatus(projectId);
       if(status!=null){
           if(status.equals("0")){
               res="待审核";
           }else if(status.equals("1")){
               res="审核通过";
           }
           else if(status.equals("2")){
               res="已拒绝";
           }
           else if(status.equals("3")){
               res="申诉中";
           }
           else if(status.equals("4")){
               res="申诉成功";
           }else if(status.equals("5")){
               res="申诉失败";
           }else if(status.equals("6")){
               res="投票中";
           }else if(status.equals("7")){
               res="投票成功";
           }
           else if(status.equals("8")){
               res="投票失败";
           }else if(status.equals("9")){
               res="更新中";
           }
       }else{
           res="未提交";
       }

        return res;
    }

    @Override
    public int updateStatus(String id, String status) {
        return inclusionExamineMapper.updateStatus(id,status);
    }

    @Override
    public int updateStatusByHash(String qmHash, String status) {
        return inclusionExamineMapper.updateStatusByHash(qmHash,status);
    }

    @Override
    public int updateClaimStatus(String qmHash, String claimStatus) {
        return inclusionExamineMapper.updateClaimStatus(qmHash,claimStatus);
    }

    /**
     * 批量删除收录审核
     *
     * @param ids 需要删除的收录审核主键
     * @return 结果
     */
    @Override
    public int deleteInclusionExamineByIds(String[] ids)
    {
        return inclusionExamineMapper.deleteInclusionExamineByIds(ids);
    }

    /**
     * 删除收录审核信息
     *
     * @param id 收录审核主键
     * @return 结果
     */
    @Override
    public int deleteInclusionExamineById(String id)
    {
        return inclusionExamineMapper.deleteInclusionExamineById(id);
    }

    @Override
    public int updateApproveAfterData(String oldProjectId, String newProjectId) {
        return projectInvestDetailsMapper.updateInvestorProjectId(oldProjectId,newProjectId);
    }
}
